#ifndef FUNCTION_H
#define FUNCTION_H
#include "snake.h"
enum MAPSIZE{
    height = 40,
    width = 120
};

void gotoxy(short x,short y){
    HANDLE hOut;
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos = {x,y};
    SetConsoleCursorPosition(hOut,pos);
}//设置输出位置

void color(int a){
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}//设置输出颜色

void HideCursor(){
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO CursorInfo;
    GetConsoleCursorInfo(handle, &CursorInfo);
    CursorInfo.bVisible = false;
    SetConsoleCursorInfo(handle,&CursorInfo);
}//设置光标属性

int wrongpos(int x,int y,deque<Snake>& s){
    for(auto snake : s){
        if(snake.get_x()==x&&snake.get_y()==y)
            return 1;
    }
    return 0;
}//判断生成新食物时，蛇身是否覆盖了食物

void print_snake(deque<Snake>& s){
    for(auto snake :s){
        gotoxy(snake.get_x()-1,snake.get_y());
        char cell=snake.get_body();
        if(cell == '*') color(11);
        else color(15);
        cout<<cell;
    }
}//输出蛇

void clear_snake(deque<Snake>& s){
    for(auto snake :s){
        gotoxy(snake.get_x()-1,snake.get_y());
        cout<<" ";
    }
}//清除蛇尾字符

int is_eat_food(deque<Snake>& s,int x,int y){
    if(s[0].get_x()==x&&s[0].get_y()==y){
        return 1;
    }
    return 0;
}//判断是否吃到食物

bool eat_self(deque<Snake>& s){
    deque<Snake>::iterator it = s.begin()+1;
    int x = s.front().get_x();
    int y = s.front().get_y();
    for(;it<s.end();it++){
        if(it->get_x()==x&&it->get_y()==y)
            return true;
    }
    return false;
}//判断是否吃到自身

double speed_up(double s){
    return s * 0.5;
};//加速
double speed_down(double s){
    return s * 2.0;
};//减速
#endif